// pages/mine/address/address.js
const app = getApp();
var url = app.globalData.url;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    typeShopping:''
  },
  //修改收货地址
  update:function(e){
    console.log(e);
    var index = e.currentTarget.dataset.index;
    wx.navigateTo({
      url: './detail/detail?index='+ index,
      success: function(res) { 
        wx.setNavigationBarTitle({
          title:"修改收货地址",
        })
      },
      fail: function(res) {},
      complete: function(res) {
      },
    })
  },
  //增加收货地址
  add:function (e) {
    const userid = app.globalData.userid;
    console.log(this.data.typeShopping);
    wx.navigateTo({
      url: './add/add?userid=' + userid,
      success: function (res) {
        wx.setNavigationBarTitle({
          title: "增加      `````````````````````````````收货地址",
        })
      },
      fail: function (res) { },
      complete: function (res) {
      },
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.data.typeShopping = options.typeShopping
    const userid = app.globalData.userid;
    wx.request({
      url: url+'getMemberAddressByUserId',
      data: {
        userId:userid
      },
      header: {
        "Content-Type": "application/json"
      },
      success: function (res) {
        console.log(res.data.object)
        that.setData({
          addresslist: res.data.object
        })
      }
    })
  },
  //确认订单选择地址
  choose:function(e){
    var index = e.currentTarget.dataset.index;
    var pages = getCurrentPages();
    var currPage = pages[pages.length - 1];  //当前页面
    var prevPage = pages[pages.length - 2]; //上一个页面   
    //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
    prevPage.setData({
      index: index
    }) 
    if (typeof Shipping === "function"){
      wx.navigateBack({
        delta: 1,
      });
      prevPage.Shipping();//执行上一个页面的方法
    }else{
      wx.navigateTo({
        url: './detail/detail?index=' + index,
        success: function (res) {
          wx.setNavigationBarTitle({
            title: "修改收货地址",
          })
        },
        fail: function (res) { },
        complete: function (res) {
        },
      })
    }
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})